package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mapper.SettingsMapper;
import com.tanhua.model.db.Settings;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
@DubboService
public class SettingsApiImpl implements SettingsApi {
    @Autowired
    private SettingsMapper settingsMapper;
    @Override
    public Settings findSetting(Long userId) {
        LambdaQueryWrapper<Settings> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Settings::getUserId,userId);
        Settings settings = settingsMapper.selectOne(wrapper);
        return settings;
    }

    @Override
    public void saveSetting(Settings settings) {
        settingsMapper.insert(settings);
    }

    @Override
    public void updateSetting(Settings settings) {
        settingsMapper.updateById(settings);
    }

    @Override
    public Settings selectSetting(Long userId) {
        LambdaQueryWrapper<Settings> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Settings::getUserId,userId);
        Settings settings = settingsMapper.selectOne(wrapper);
        return settings;
    }
}
